package test.login;


import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class login {
    private static String URL;
    private static String DRIVER;
    private static String USERNAME;
    private static String PASSWORD;
    private static Connection conn;
    private static PreparedStatement ps=null;
    private static ResultSet rs=null;
    static{
        try{
            Properties properties = new Properties ( );
            InputStream is = login.class.getClassLoader ( ).getResourceAsStream ("mysqlme.properties");
            properties.load (is);
          URL=properties.getProperty ("url");
          DRIVER=properties.getProperty ("driver");
          USERNAME=properties.getProperty ("username");
          PASSWORD=properties.getProperty ("password");
          Class.forName (DRIVER);
          conn=DriverManager.getConnection (URL,USERNAME,PASSWORD);


        }catch(Exception e){
            e.printStackTrace ();

            }
    }
    public static void main(String[] args) throws SQLException {
        String root = update ("root", "55555");
        System.out.println (root );
//        String root = delete ("root");
//        System.out.println (root );

    }
    public static String update(String zhanghao,String mima) throws SQLException {
        String sql="update hao set mima=? where zhanghao=?";
        PreparedStatement ps = conn.prepareStatement (sql);
        ps.setString (1,mima);
        ps.setString (2,zhanghao);
        int i = ps.executeUpdate ( );

        if (i!=1){

            return "修改失败";
        }
        return "修改成功";
    }
    public static String delete(String zhanghao) throws SQLException {
        String sql="delete from hao where zhanghao=?";
        PreparedStatement ps = conn.prepareStatement (sql);
        ps.setString (1,zhanghao);
        int i = ps.executeUpdate ( );
        if (i!=1){
            return "修改失败";
        }
        return "修改成功";

    }

}
